package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.bean.ActivityBean;
import cn.com.ddapp.ddm.util.NetUtils;


/**
 * Created by Administrator on 2016/7/30 0030.
 */
public class NewGoodsOutAdapter extends BaseAdapter {//限时抢购的Adapter
    private Context context;
    private List<ActivityBean.PromotionListBean> promotion;

    public NewGoodsOutAdapter(Context context, List<ActivityBean.PromotionListBean> promotion) {
        this.context = context;
        this.promotion = promotion;
    }

    @Override
    public int getCount() {
        return promotion.size();
    }

    @Override
    public Object getItem(int position) {
        return promotion.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_item_outtime, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String []aa=promotion.get(position).getHeadImg().split("\\.");
        StringBuffer b=new StringBuffer();
        b.append(aa[0]).append("_360.").append(aa[1]);
       Glide.with(context).load(OKUtilAPI.imgBaseUrl+b).into(holder.imageGood);
       holder.newsData.setText(promotion.get(position).getName());
        holder.momney.setText("￥"+ NetUtils.setDecimal(promotion.get(position).getPriceFlash()));
        holder.discountpirce.setText("￥"+NetUtils.setDecimal(promotion.get(position).getPrice()));
        holder.discountpirce.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG);//textView加横线
        holder.limitnum.setText("限量"+promotion.get(position).getMax()+"件");

        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.imageGood)
        ImageView imageGood;
        @BindView(R.id.newsData)
        TextView newsData;
        @BindView(R.id.pircText)
        TextView pircText;
        @BindView(R.id.momney)
        TextView momney;
        @BindView(R.id.markepirce)
        TextView markepirce;
        @BindView(R.id.discountpirce)
        TextView discountpirce;
        @BindView(R.id.limitnum)
        TextView limitnum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
